﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Terminal.Advanced_AEUC_settings_controls.Settings_AUX;

namespace Terminal.Advanced_AEUC_settings_controls.Scripting
{
    class ScrPrint : ScrBasicAction
    {
        /// <summary>
        /// Public constructor for the script action
        /// </summary>
        /// <param name="iDispName">Action display text</param>
        /// <param name="iUsageHelp">Usage help and comments text for the action</param>
        public ScrPrint(string iDispName, string iUsageHelp)
            : base(iDispName, iUsageHelp)
        {
            usageHelp += "Input params: object to print off.\n";
        }

        /// <summary>
        /// Perform the action using specified parameters.
        /// </summary>
        /// <param name="paramList">List of the input/output parameters for the action</param>
        /// <returns>True if action is succesful</returns>
        public override bool Do(List<object> paramList)
        {
            if (breakPoint)
                WaitUserInput();

            if (paramList.Count > 1 && paramList[0].GetType() == typeof(ScrRunTimeEnv))
            {
                ScrRunTimeEnv rte = (ScrRunTimeEnv)(paramList[0]);

                string printOut = "--- ";
                for (int i = 1; i < paramList.Count; i++)
                {
                    object obj2Print = (object)(paramList[i]);
                    if (obj2Print.GetType() == typeof(GenMSG))
                        printOut += ((GenMSG)obj2Print).msgDisplayName;
                    else if (obj2Print.GetType() == typeof(GenPayloadStruct))
                        printOut += ((GenPayloadStruct)obj2Print).ContentsString(true);
                    else if (obj2Print.GetType() == typeof(char[]))
                        printOut += new string(((char[])obj2Print));
                    else if (obj2Print.GetType() == typeof(int))
                        printOut += ((int)obj2Print).ToString();
                    else
                        printOut += obj2Print.ToString();

                    printOut += " ";
                }
                printOut += " ---";
                rte.Print(printOut);
                return true;
            }

            return false;
        }
        /// <summary>
        /// Returns a List containing objects of the parameter list required for the Do function.
        /// </summary>
        /// <returns>List of parameter objects</returns>
        public override List<Type> GetParamList()
        {
            List<Type> paramList = new List<Type>();
            paramList.Add(typeof(ScrRunTimeEnv));
            paramList.Add(typeof(ScrVarArgListType));
            paramList.Add(typeof(object));

            return paramList;
        }
    }
}

